using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CardManager : MonoBehaviour
{
    public static CardManager instance;

    private void Awake()
    {
        if (instance == null)
            instance = this;
        else
            Destroy(gameObject);
    }

    public DeckMono PlayerDeck;
    bool ifStart = false;

    public void InitPlayerDeckOnGameStart()
    {
        if (ifStart)
            return;
        ifStart = true;
        PlayerDeck.InitDeckByPrefabDatas();
    }

    public List<Pawn> PawnCardPool = new List<Pawn>();

    public Pawn SelectedPawn;

    public ChooseWindow chooseWindow;

    public void StartChooseNewPawn()
    {
        int pawn1index = Random.Range(0, PawnCardPool.Count);
        int pawn2index = Random.Range(0, PawnCardPool.Count);

        int count = 0;

        while (pawn2index == pawn1index && count < 100)
        {

            pawn2index = Random.Range(0, PawnCardPool.Count);
            count++;
        }

        int pawn3index = Random.Range(0, PawnCardPool.Count);
        while ((pawn3index == pawn1index || pawn3index == pawn2index) && count < 100)
        {
            pawn3index = Random.Range(0, PawnCardPool.Count);
            count++;
        }

        chooseWindow.ShowWaitChooseWindow(new List<Pawn>() { PawnCardPool[pawn1index], PawnCardPool[pawn2index], PawnCardPool[pawn3index] });
    }

    public void FinishChoose()
    {
        if (SelectedPawn == null)
            return;
        if (PlayerDeck.AddNewCard(SelectedPawn))
        {
            SelectedPawn = null;
            LevelManager.instance.OnChooseEndButton();
        }
        else
            return;
    }

    public void SkipChoose()
    {
        SelectedPawn = null;

        LevelManager.instance.OnChooseEndButton();
    }
}
